#!/bin/bash
### BEGIN INIT INFO
# Provides:          fdsmastergo
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: FDS Master Go Service
# Description:       Start/Stop FDS Master Go Services
### END INIT INFO

# 加载环境变量
if [ -f /etc/profile.d/fdsmastergo.sh ]; then
    source /etc/profile.d/fdsmastergo.sh
fi

case "$1" in
    start)
        echo "启动 FDS Master Go 服务..."
        if [ -x "$FDSMASTERGO_SERVICE_DIR/micro_start.sh" ]; then
            $FDSMASTERGO_SERVICE_DIR/micro_start.sh
        else
            echo "错误: 未找到启动脚本"
            exit 1
        fi
        ;;
    stop)
        echo "停止 FDS Master Go 服务..."
        if [ -x "$FDSMASTERGO_SERVICE_DIR/micro_stop.sh" ]; then
            $FDSMASTERGO_SERVICE_DIR/micro_stop.sh
        else
            echo "错误: 未找到停止脚本"
            exit 1
        fi
        ;;
    restart)
        echo "重启 FDS Master Go 服务..."
        if [ -x "$FDSMASTERGO_SERVICE_DIR/micro_restart.sh" ]; then
            $FDSMASTERGO_SERVICE_DIR/micro_restart.sh
        else
            echo "错误: 未找到重启脚本"
            exit 1
        fi
        ;;
    status)
        echo "检查 FDS Master Go 服务状态..."
        if [ -x "$FDSMASTERGO_SERVICE_DIR/micro_status.sh" ]; then
            $FDSMASTERGO_SERVICE_DIR/micro_status.sh
        else
            echo "错误: 未找到状态检查脚本"
            exit 1
        fi
        ;;
    *)
        echo "用法: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac

exit 0 